﻿@using Smartstore.Web.Models.Common;
@using Smartstore.Web.Models.Cart;

@model ShoppingCartModel.OrderReviewDataModel

@if (!Model.Display)
{
    return;
}

@{
    async Task RenderAddress(AddressModel address)
    {
        var cityStateZip = address.GetFormattedCityStateZip();

        <div class="mb-2">
            <div sm-if="address.CompanyEnabled && address.Company.HasValue()" class="company">
                @address.Company
            </div>
            <div class="name">
                @address.GetFormattedName()
            </div>
            <div sm-if="address.StreetAddressEnabled && address.Address1.HasValue()" class="address1">
                @address.Address1
            </div>
            <div sm-if="address.StreetAddress2Enabled && address.Address2.HasValue()" class="address2">
                @address.Address2
            </div>
            <div sm-if="cityStateZip.HasValue()" class="city-state-zip">
                @Html.Raw(cityStateZip)
            </div>
            <div sm-if="address.CountryEnabled && address.CountryName.HasValue()" class="country">
                @address.CountryName
            </div>
        </div>

        <div class="email">
            <span class="pr-1">@T("Order.Email"):</span>
            <span>@address.Email</span>
        </div>

        <div sm-if="address.PhoneEnabled && address.PhoneNumber.HasValue()" class="phone">
            <span>@T("Order.Phone"):</span>
            <span>@address.PhoneNumber</span>
        </div>

        <div sm-if="address.FaxEnabled && address.FaxNumber.HasValue()" class="fax">
            <span>@T("Order.Fax"):</span>
            <span>@address.FaxNumber</span>
        </div>
    }
}

<div class="card card-body order-review-data-box mb-3">
    <div class="row">
        <div class="col-md-8">
            <div class="row">
                <div class="col mb-4 mb-lg-0 billinginfo">
                    <div class="row sm-gutters">
                        <div class="col">
                            <div class="heading">
                                <h5 class="heading-title font-weight-medium">@T("Order.BillingAddress")</h5>
                            </div>
                        </div>
                        <div class="col col-auto">
                            <a asp-action="BillingAddress" asp-controller="Checkout" class="btn btn-primary btn-sm change-checkout-data change-billing-address">
                                @T("Common.Change")
                            </a>
                        </div>
                    </div>
                    @{ await RenderAddress(Model.BillingAddress); }
                </div>
                <div sm-if="Model.IsShippable && Model.ShippingAddress != null" class="col mb-4 mb-lg-0 shippinginfo">
                    <div class="row sm-gutters">
                        <div class="col">
                            <div class="heading">
                                <h5 class="heading-title font-weight-medium">@T("Order.ShippingAddress")</h5>
                            </div>
                        </div>
                        <div class="col col-auto">
                            <a asp-action="ShippingAddress" asp-controller="Checkout" class="btn btn-primary btn-sm change-checkout-data change-shipping-address">
                                @T("Common.Change")
                            </a>
                        </div>
                    </div>
                    @{ await RenderAddress(Model.ShippingAddress); }
                </div>
            </div>
        </div>
        <div sm-if="Model.PaymentMethod.HasValue() || (Model.IsShippable && Model.ShippingMethod.HasValue())" class="col-md-4">
            <div class="row">
                <div class="col">
                    @if (Model.IsShippable && Model.ShippingMethod.HasValue())
                    {
                        <div class="row sm-gutters">
                            <div class="col">
                                <div class="heading">
                                    <h5 class="heading-title font-weight-medium">@T("Order.ShippingMethod")</h5>
                                </div>
                            </div>
                            <div sm-if="Model.DisplayShippingMethodChangeOption" class="col col-auto">
                                <a asp-action="ShippingMethod" asp-controller="Checkout" class="btn btn-primary btn-sm change-checkout-data change-shipping-method">
                                    @T("Common.Change")
                                </a>
                            </div>
                        </div>
                        <p>@Model.ShippingMethod</p>
                    }
                    @if (Model.PaymentMethod.HasValue() && !Model.IsPaymentSelectionSkipped)
                    {
                        <div class="row sm-gutters">
                            <div class="col">
                                <div class="heading">
                                    <h5 class="heading-title font-weight-medium">@T("Order.PaymentMethod")</h5>
                                </div>
                            </div>
                            <div sm-if="Model.DisplayPaymentMethodChangeOption" class="col col-auto">
                                <a asp-action="PaymentMethod" asp-controller="Checkout" class="btn btn-primary btn-sm change-checkout-data change-payment-method">
                                    @T("Common.Change")
                                </a>
                            </div>
                        </div>
                        <p>@Model.PaymentMethod</p>
                        <div sm-if="Model.PaymentSummary.HasValue()" class="text-muted">@Model.PaymentSummary</div>
                    }
                </div>
            </div>
        </div>
    </div>

    <div class="row d-none">
        <div class="billinginfo col-md-6 mb-3">
            <div class="card">
                <div class="card-header d-flex flex-nowrap justify-content-between">
                    <h5 class="m-0">@T("Order.BillingAddress")</h5>
                    <a asp-action="BillingAddress" asp-controller="Checkout" class="change-checkout-data change-billing-address">
                        @T("Common.Change")
                    </a>
                </div>
                <div class="card-body">
                    @{ await RenderAddress(Model.BillingAddress); }
                </div>
            </div>
        </div>

        <div sm-if="Model.IsShippable" class="shippinginfo col-md-6 mb-3">
            <div class="card">
                <div class="card-header d-flex flex-nowrap justify-content-between">
                    <h5 class="m-0">@T("Order.ShippingAddress")</h5>
                    <a asp-action="ShippingAddress" asp-controller="Checkout" class="change-checkout-data change-shipping-address">
                        @T("Common.Change")
                    </a>
                </div>
                <div class="card-body">
                    @{ await RenderAddress(Model.ShippingAddress); }
                </div>
            </div>
        </div>
    </div>

    <div sm-if="Model.PaymentMethod.HasValue()" class="payment-method mb-3 d-none">
        <div class="card">
            <div class="card-header d-flex flex-nowrap justify-content-between">
                <h5 class="m-0">@T("Order.PaymentMethod")</h5>
                @if (!Model.IsPaymentSelectionSkipped)
                {
                    <a asp-action="PaymentMethod" asp-controller="Checkout" class="change-checkout-data change-payment-method">
                        @T("Common.Change")
                    </a>
                }
            </div>
            <div class="card-body">
                @Model.PaymentMethod
                <span sm-if="Model.PaymentSummary.HasValue()" class="text-muted">@Model.PaymentSummary</span>
            </div>
        </div>
    </div>
    <div sm-if="Model.ShippingMethod.HasValue()" class="shipping-method mb-3 d-none">
        <div class="card">
            <div class="card-header d-flex flex-nowrap justify-content-between">
                <h5 class="m-0">@T("Order.ShippingMethod")</h5>
                <a asp-action="ShippingMethod" asp-controller="Checkout" class="change-checkout-data change-shipping-method">
                    @T("Common.Change")
                </a>
            </div>
            <div class="card-body">
                @Model.ShippingMethod
            </div>
        </div>
    </div>
</div>